/**
 * My simple header template from child directory
 * SnowRescueService.java - ${projectName} - ${organizationName} - ${inceptionYear}
 */
package mantaince;

/*
 * #%L
 * Ability-tester
 * %%
 * Copyright (C) 2014 SERKU
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

/**
 * User: Yahor Kastsialei
 * Date: 11/6/13
 * Time: 2:21 PM
 */
public class SnowRescueService {
    WeatherForecastService weatherForecastService;
    MunicipalServices municipalServices;
    PressService pressService;

    public SnowRescueService(WeatherForecastService weatherForecastService, MunicipalServices municipalServices, PressService pressService) {
        this.weatherForecastService = weatherForecastService;
        this.municipalServices = municipalServices;
        this.pressService = pressService;
    }

    public void checkForecastAndRescue() {
        int temperature = weatherForecastService.getAverageTemperatureInCelsius();
        int snowLevel = weatherForecastService.getSnowFallHeightInMM();
        if (temperature < 0 && temperature >= -10) {
            municipalServices.sendSander();
        }
        if (snowLevel >= 3) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
        }
        if (snowLevel >= 5) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
        }
        if (temperature < -10 && snowLevel >= 10) {
            try {
                municipalServices.sendSnowplow();
            } catch (SnowplowMalfunctioningException exception) {
                municipalServices.sendSnowplow();
            }
            municipalServices.sendSander();
            pressService.sendWeatherAlert();
        }
    }

}